package com.rural.bus.driver.view;

import java.util.Arrays;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.rural.bus.driver.R;

public class SetIsSpecialCarDialog extends Dialog implements View.OnClickListener {
	private Button btn_confirm, btn_cancel;
	private WheelView main_wv;
	private static final String[] datas = new String[] { "是", "否"};

	private OnDialogDismissListener listener;
	private int selectedItem;

	public interface OnDialogDismissListener {
		void onConfirmClicked(int index);

		void onCancelClicked();
	}

	public SetIsSpecialCarDialog(Context context, OnDialogDismissListener listener) {
		super(context, R.style.common_alert_dialog);
		this.listener = listener;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_set_is_special_car_dialog);
		initView();
	}

	private void initView() {
		main_wv = (WheelView) findViewById(R.id.main_wv);
		btn_confirm = (Button) findViewById(R.id.btn_confirm);
		btn_confirm.setOnClickListener(this);
		btn_cancel = (Button) findViewById(R.id.btn_cancel);
		btn_cancel.setOnClickListener(this);
		
		main_wv.setOffset(1);
		selectedItem = 1;
		main_wv.setItems(Arrays.asList(datas));
		main_wv.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
			@Override
			public void onSelected(int selectedIndex, String item) {
				Log.d("driver", "selectedIndex: " + selectedIndex + ", item: " + item);
				selectedItem = selectedIndex;
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_confirm:
			if (listener != null) {
				dismiss();
				listener.onConfirmClicked(selectedItem);
			}
			break;
		case R.id.btn_cancel:
			if (listener != null) {
				dismiss();
			}
			break;
		default:
			break;
		}
	}
	
	

}
